package com.csiec.clock.adpter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.csiec.clock.R;
import com.csiec.clock.bean.people.People;

import java.util.List;

public class ClockInfoAdapter extends RecyclerView.Adapter<ClockInfoAdapter.ViewHolder> {

    private final String TAG = ClockInfoAdapter.class.getSimpleName();

    private List<People> allPeoples;
    private Activity activity;

    public ClockInfoAdapter(List<People> allClock, Activity activity) {
        this.allPeoples = allClock;
        this.activity = activity;
    }

    public ClockInfoAdapter() {

    }

    public void setAllPeoples(List<People> allPeoples) {
        this.allPeoples = allPeoples;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View itemView;
        itemView = layoutInflater.inflate(R.layout.cell_card_clock_info, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        People people = allPeoples.get(position);
        holder.num.setText(people.getSid());
        holder.name.setText(people.getSname());
        holder.time.setText(people.getDatetime());
        holder.is_clock.setText(people.getWhetherPunch());
    }

    @Override
    public int getItemCount() {
        return allPeoples.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView num, name, time, is_clock;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            num = itemView.findViewById(R.id.info_num);
            name = itemView.findViewById(R.id.clock_num);
            time = itemView.findViewById(R.id.info_time);
            is_clock = itemView.findViewById(R.id.info_daka);
        }
    }

}
